package com.ruoyi.common.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.framework.web.domain.BaseEntity;

import java.util.List;
import java.util.Map;

public class MybatisUtils    {

    public static <T extends BaseEntity> List<T> list(BaseMapper<T> mapper, T t){
        LambdaQueryWrapper<T> lambdaQueryWrapper = new LambdaQueryWrapper<>(t);
        Map<String, Object> params = t.getParams();
        Object beginTime = params.get("beginTime");
        Object endTime = params.get("endTime");
        lambdaQueryWrapper.between((beginTime!= null && endTime!= null), T::getCreateTime, beginTime, endTime);
        return mapper.selectList(lambdaQueryWrapper);
    }
}
